package com.xdq.spring.service;

import com.xdq.spring.model.Car;
import com.xdq.spring.model.Worker;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("carFactory")
@Scope("singleton")
public class CarFactory{

    private List<Worker> workers=new ArrayList<>();

    private EngineProducer engineProducer;

    private LightProducer lightProducer;

    private TransmissionProducer transmissionProducer;

    private WheelProducer wheelProducer;

    private SkeletonProducer skeletonProducer;

    @Value("${car.factory.address}")
    private String address;

    public CarFactory (Worker worker){
        System.out.println("CarFactory被实例化了，我的地址为："+this.address);
        this.workers.add(worker);
    }

    public CarFactory(){
        System.out.println("CarFactory被实例化了，我的地址为："+this.address);
    }

    public Car productCar(){
        workers.get(0).setCarFactory(this);
        Car car=workers.get(0).assemble();
        return car;
    }

    public void addWorker(Worker worker){
        worker.setCarFactory(this);
        this.workers.add(worker);
    }

    public List<Worker> getWorkers() {
        return workers;
    }

    public void setWorkers(List<Worker> workers) {
        this.workers = workers;
    }

    public EngineProducer getEngineProducer() {
        return engineProducer;
    }

    public void setEngineProducer(EngineProducer engineProducer) {
        this.engineProducer = engineProducer;
    }

    public LightProducer getLightProducer() {
        return lightProducer;
    }

    public void setLightProducer(LightProducer lightProducer) {
        this.lightProducer = lightProducer;
    }

    public TransmissionProducer getTransmissionProducer() {
        return transmissionProducer;
    }

    public void setTransmissionProducer(TransmissionProducer transmissionProducer) {
        this.transmissionProducer = transmissionProducer;
    }

    public WheelProducer getWheelProducer() {
        return wheelProducer;
    }

    public void setWheelProducer(WheelProducer wheelProducer) {
        this.wheelProducer = wheelProducer;
    }

    public SkeletonProducer getSkeletonProducer() {
        return skeletonProducer;
    }

    public void setSkeletonProducer(SkeletonProducer skeletonProducer) {
        this.skeletonProducer = skeletonProducer;
    }


    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}
